package com.yiwei.zhh.api.requestInfo;

import com.yiwei.zhh.api.Api;
import com.yiwei.zhh.api.bean.NewBeginApplyBean;
import com.yiwei.zhh.api.bean.NewV2BeginApplyBean;
import com.yiwei.zhh.api.callback.BeginApplyContract;
import com.yiwei.zhh.util.Network;
import com.yiwei.zhh.util.RxLifeUtil;
import com.yiwei.zhh.util.ToastUtil;

/**
 * Created by Administrator on 2017/5/14.
 */

public class BeginApplyRequest extends BaseRequest<BeginApplyContract.View> implements BeginApplyContract.Presenter<BeginApplyContract.View> {

    public static BeginApplyRequest create() {
        return new BeginApplyRequest();
    }


    @Override
    public void beginApply(String dealId) {
        if (!Network.checkNetwork(BaseContext)) {
            ToastUtil.makeText(BaseContext, networkFail).show();
            return;
        }
        mView.onRequestStart();
        NewBeginApplyBean bean = new NewBeginApplyBean();
        bean.id = dealId;
        Api.api_service.getNewBeginApplyInfo(bean).compose(RxLifeUtil.checkOn(BaseContext)).
                doFinally(() -> {
                    try {
                        mView.complete();
                    } catch (NullPointerException e) {

                    }
                }).
                subscribe(result -> {
                    mView.beginApplySuccess(result);
                });
    }

    @Override
    public void getDealTypeInfo() {
        if (!Network.checkNetwork(BaseContext)) {
            ToastUtil.makeText(BaseContext, networkFail).show();
            return;
        }
        mView.onRequestStart();
        Api.api_service.getDealTypeInfo().compose(RxLifeUtil.checkOn(BaseContext)).
                doFinally(() -> {
                    try {
                        mView.complete();
                    } catch (NullPointerException e) {

                    }
                }).
                subscribe(result -> {
                    mView.getDealTypeInfoSuccess(result);
                });
    }

    @Override
    public void getNewBeginApply(String id) {
        if (!Network.checkNetwork(BaseContext)) {
            ToastUtil.makeText(BaseContext, networkFail).show();
            return;
        }
        mView.onRequestStart();
        NewV2BeginApplyBean bean = new NewV2BeginApplyBean();
        bean.id = id;
        Api.api_service.getNewBeginApply(bean).compose(RxLifeUtil.checkOn(BaseContext)).
                doFinally(() -> {
                    try {
                        mView.complete();
                    } catch (NullPointerException e) {

                    }
                }).
                subscribe(result -> {
                    mView.getNewBeginApplySuccess(result);
                });
    }

    @Override
    public void getDealBefore() {
        if (!Network.checkNetwork(BaseContext)) {
            ToastUtil.makeText(BaseContext, networkFail).show();
            return;
        }
        mView.onRequestStart();
        Api.api_service.getDealBefore().compose(RxLifeUtil.checkOn(BaseContext)).
                doFinally(() -> {
                    try {
//                        mView.complete();
                    } catch (NullPointerException e) {

                    }
                }).
                subscribe(result -> {
                    mView.getDealBeforeSuccess(result);
                });
    }
}
